
#ifndef CALCULATOR_HPP
#define CALCULATOR_HPP

#include <iostream>
#include <string>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }
    response Execute(const request &req)
    {
        // 我们拿到的都是结构化的数据，拿到的不就是类对象吗！！！
        response resp;
        switch (req.Oper())
        {
        case '+':
            resp.Setresult(req.X() + req.Y());
            break;
        case '-':
            resp.Setresult(req.X() - req.Y());
            break;
        case '*':
            resp.Setresult(req.X() * req.Y());
            break;
        case '/':
        {
            if (req.Y() == 0)
            {
                resp.Setcode(1); // 1 就是除0
            }
            else
            {
                resp.Setresult(req.X() / req.Y());
            }
        }
        break;
        case '%':
        {
            if (req.Y() == 0)
            {
                resp.Setcode(2); // 2 就是mod 0
            }
            else
            {
                resp.Setresult(req.X() % req.Y());
            }
        }
        break;
        default:
            resp.Setcode(3); // 3 用户发来的计算类型，无法识别
            break;
        }
        return resp;
    }
    ~Calculator()
    {
    }
};

#endif